# import keyword
import sys
import getopt
# from sys import argv, path
import sklearn
import numpy as np
import pandas as pd
from pandas import Series, DataFrame
from pandasql import sqldf, load_meat, load_births
import random

def addone(score):
    return score + 1

if __name__ == "__main__":
    # print("Hello, World!")
    # print(keyword.kwlist)

    '''
    str = '123456789'
    print(str)
    print(str[0:-1])
    print(str[0])
    print(str[2:5])
    print(str[2:])
    print(str[1:5:2])
    print(str * 2)
    print(str + '你好')

    print('--------')
    print('hello\nrunoob')
    print(r'hello\nrunoob')
    '''

    # input("\n\n按下 enter 键后退出。")

    # x = 'runoob'; sys.stdout.write(x + '\n')

    '''
    x = 'a'
    y = 'b'

    print(x)
    print(y)

    print('--------')
    print( x, end=" ")
    print( y, end=" ")
    print()
    '''

    """
    print('命令行参数为:')
    for i in sys.argv:
        print(i)
    print('\n python 路径为', sys.path)
    """

    # print('path:', path)

    """
    print('参数个数为:', len(sys.argv), '个参数。')
    print('参数列表:', str(sys.argv))
    print('脚本名:', str(sys.argv[0]))
    """

    """
    counter = 100
    miles = 1000.0
    name = "ronoob"
    print(counter)
    print(miles)
    print(name)
    """

    '''
    name = input("What's your name?\n")
    sum = 100 + 100
    print('hello,%s' %name)
    print('sum = %d' %sum)
    '''

    '''
    scoreStr = input("input score:\n")
    score = int(scoreStr) # 字符串转数字
    if score >= 90:
        print('Excellent')
    else:
        if score < 60:
            print('Fail')
        else:
            print('Good Job')
    '''

    '''
    sum = 0
    for number in range(11):
        sum = sum + number
    print(sum)
    '''

    '''
    sum = 0
    number = 1
    while number < 11:
        sum = sum + number
        number = number + 1
    print(sum)
    '''

    '''
    lists = ['a', 'b', 'c']
    lists.append('d')
    print(lists)
    print(len(lists))
    lists.insert(0, 'mm')
    print(lists)
    lists.pop()
    print(lists)
    '''

    '''
    tuples = ('tupleA', 'tupleB')
    print(tuples[0])
    '''

    '''
    score = {'guanyu':95, 'zhangfei':96}
    score['zhaoyun'] = 98
    print(score)
    score.pop('zhangfei')
    print(score)
    print('guanyu' in score)
    print(score.get('guanyu'))
    print(score.get('yase', 99))
    print(score)
    '''
    '''
    s = set(['a', 'b', 'c'])
    s.add('d')
    s.remove('b')
    print(s)
    print('c' in s)
    '''

    # print(addone(99))

    '''
    while True:
        try:
            line = input()
            a = line.split()
            print(int(a[0]) + int(a[1]))
        except:
            break
    '''

    '''
    sum = 0
    for number in range(1, 100, 2):
        print(number)
        sum = sum + number
    print(sum)
    '''

    '''
    sum = 0
    number = 1
    while number < 100:
        print(number)
        sum = sum + number
        number = number + 2
    print(sum)
    '''

    '''
    a = np.array([1, 2, 3])
    b = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
    b[1, 1] = 10
    print(a.shape)
    print(b.shape)
    print(a.dtype)
    print(b)
    '''

    '''
    persontype = np.dtype({
        'names':['name', 'age', 'chinese', 'math', 'english'],
        'formats':['S32', 'i', 'i', 'i', 'i']
    })
    peoples = np.array([("ZhangFei", 32, 75, 100, 90), ("GuanYu", 24, 85, 96, 88.5),
                        ("ZhaoYun", 28, 85, 92, 96.5), ("HuangZhong", 29, 65, 85, 100)], dtype=persontype)

    ages = peoples[:]['age']
    chineses = peoples[:]['chinese']
    maths = peoples[:]['math']
    englishs = peoples[:]['english']
    print(np.mean(ages))
    print(np.mean(chineses))
    print(np.mean(maths))
    print(np.mean(englishs))
    '''

    '''
    x1 = np.arange(1, 11, 2)
    x2 = np.linspace(1, 9, 5)
    print(x1)
    print(x2)
    print(np.add(x1, x2))
    print(np.subtract(x1, x2))
    print(np.multiply(x1, x2))
    print(np.divide(x1, x2))
    print(np.power(x1, x2))
    print(np.remainder(x1, x2))
    print(np.mod(x1, x2))
    '''

    # a = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
    # print(np.amin(a))
    # print(np.amin(a, 0))
    # print(np.amin(a, 1))
    # print(np.amax(a))
    # print(np.amax(a, 0))
    # print(np.amax(a, 1))
    # print(np.ptp(a))
    # print(np.ptp(a, 0))
    # print(np.ptp(a, 1))
    # print(np.percentile(a, 50))
    # print(np.percentile(a, 50, axis = 0))
    # print(np.percentile(a, 50, axis = 1))
    # print(np.median(a))
    # print(np.median(a, axis = 0))
    # print(np.median(a, axis = 1))
    # print(np.mean(a))
    # print(np.mean(a, axis = 0))
    # print(np.mean(a, axis = 1))

    '''
    a = np.array([1, 2, 3, 4])
    wts = np.array([1, 2, 3, 4])
    print(np.average(a))
    print(np.average(a, weights=wts))
    '''

    '''
    a = np.array([1, 2, 3, 4])
    print(np.std(a)) # 标准差
    print(np.var(a)) # 方差
    '''

    '''
    a = np.array([[4,3,2],[2,4,1]])
    print(np.sort(a))
    print(np.sort(a, axis=None))
    print(np.sort(a, axis=0))
    print(np.sort(a, axis=1))
    '''

    '''
    persontype = np.dtype({
        'names':['name', 'chinese', 'english', 'math'],
        'formats':['S32', 'i', 'i', 'i']
    })
    peoples = np.array([("ZhangFei", 66, 65, 30), ("GuanYu", 95, 85, 98), ("ZhaoYun", 93, 92, 96),
                        ("HuangZhong", 90, 88, 77), ("DianWei", 80, 90, 90)], dtype=persontype)
    name = peoples[:]['name']
    chineses = peoples[:]['chinese']
    englishs = peoples[:]['english']
    maths = peoples[:]['math']

    def show(name, cj):
        print('{}|  {}  |  {}  |  {}  |  {}  |  {}'.format(name, np.mean(cj), np.min(cj), np.max(cj), np.var(cj), np.std(cj)))

    print("科目| 平均成绩 | 最小成绩 | 最大成绩 |  方差  |  标准差")
    show("语文", chineses)
    show("英语", englishs)
    show("数学", maths)

    print("排名:")
    ranking = sorted(peoples, key=lambda x:x[1]+x[2]+x[3], reverse=True)
    print(ranking)
    '''

    '''
    x1 = Series([1, 2, 3, 4])
    x2 = Series(data=[1, 2, 3, 4], index=['a', 'b', 'c', 'd'])
    print(x1)
    print(x2)
    '''

    '''
    d = {'a':1, 'b':2, 'c':3, 'd':4}
    x3 = Series(d)
    print(x3)
    '''

    '''
    data = {'Chinese': [66, 95, 93, 90, 80], 'English': [65, 85, 92, 88, 90], 'Math': [30, 98, 96, 77, 90]}
    df1 = DataFrame(data)
    df2 = DataFrame(data, index=['ZhangFei', 'Guanyu', 'ZhaoYun', 'HuangZhong', 'DianWei'], columns=['English', 'Math', 'Chinese'])
    print(df1)
    print(df2)
    '''

    '''
    score = DataFrame(pd.read_excel('data.csv'))
    score.to_excel('data1.csv')
    print(score)
    '''

    '''
    data = {'Chinese': [66, 95, 93, 90, 80], 'English': [65, 85, 92, 88, 90], 'Math': [30, 98, 96, 77, 90]}
    df2 = DataFrame(data, index=['ZhangFei', 'Guanyu', 'ZhaoYun', 'HuangZhong', 'DianWei'],
                    columns=['English', 'Math', 'Chinese'])
    print(df2)
    '''

    # df2 = df2.drop_duplicates();

    # df2.rename(columns={'Chinese': 'YuWen', 'English': 'YingYu'}, inplace=True)
    #print(df2)

    # df2 = df2.drop(columns=['Chinese'])
    # print(df2)
    # df2 = df2.drop(index=['ZhangFei'])
    # print(df2)

    # df1 = DataFrame({'name': ['ZhangFei', 'GuanYu', 'a', 'b', 'c'], 'data1': range(5)})
    # df2 = DataFrame({'name': ['ZhangFei', 'GuanYu', 'A', 'B', 'C'], 'data2': range(5)})

    # df3 = pd.merge(df1, df2, on='name')
    # df3 = pd.merge(df1, df2, how='inner')
    # df3 = pd.merge(df1, df2, how='left')
    # df3 = pd.merge(df1, df2, how='right')
    # df3 = pd.merge(df1, df2, how='outer')
    # print(df3)

    # print(df1.describe())
    # print(df2.describe())

    '''
    df1 = DataFrame({'name': ['ZhangFei', 'GuanYu', 'a', 'b', 'c'], 'data1': range(5)})
    pysqldf = lambda sql: sqldf(sql, globals())
    sql = "select * from df1 where name ='ZhangFei'"
    print(pysqldf(sql))
    '''

    '''
    df6 = pd.DataFrame(
        {"语文": [66, 95, 95, 90, 80, 80], "数学": [65, 85, 92, 88, 90, 90], "英语": [np.nan, 98, 96, 77, 90, 90]},
        index=['张飞', '关羽', '赵云', '黄忠', '典韦', '典韦']
    )
    print(df6)
    df7 = df6.drop_duplicates();
    print(df7)
    df8 = df7.fillna(df7['英语'].mean())
    print(df8)
    df8['sum'] = [df8.loc[name].sum() for name in df8.index]
    print(df8)
    df9 = df8.sort_values(by="sum", ascending=False)
    print(df9)
    '''

    '''
    symbol = [1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4]
    win = 0
    for i in range(1000000):
        temp = [random.choice(symbol), random.choice(symbol), random.choice(symbol)]
        if temp == [1, 1, 1]:
            win += 80
        elif temp == [2, 2, 2]:
            win += 30
        elif temp == [3, 3, 3]:
            win += 5
        elif temp == [4, 4, 4]:
            win += 5
    print(win / 1000000)
    '''

    print("wjw")

